package org.smart4j.framework.aspect;

import java.lang.reflect.Method;

import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.annotation.Aspect;
import org.smart4j.framework.annotation.Controller;
import org.smart4j.framework.proxy.AspectProxy;

/**
 * description: 拦截 所有 Controller 方法
 * @version v1.0
 * @author w
 * @date 2018年9月27日下午3:48:25
 */
@Aspect(value = Controller.class)
public class ControllerAspect extends AspectProxy {
	private static final Logger logger = LoggerFactory.getLogger(ControllerAspect.class);
	
	private long begin;
	
	@Override
	protected void before(Class<?> targetClass, Method targetMethod, Object[] methodParams) {
		logger.debug("----------- begin --------- ");
		logger.debug(String.format("class: %s", targetClass.getName()));
		logger.debug(String.format("method: %s", targetMethod.getName()));
		begin = System.currentTimeMillis();
	}
	
	@Override
	protected void after(Class<?> targetClass, Method targetMethod, Object[] methodParams, Object result) {
		logger.debug(String.format("time: %dms", (System.currentTimeMillis()-begin)));
		logger.debug("----------- end ---------- ");
	}
	
	
}
